/*
 * StoreBO.java
 *
 * Created on March 5, 2007, 8:09 PM
 *
 */

package edu.byu.isys413.group1E.data;

import edu.byu.isys413.group1E.ConnectionPoolException;
import edu.byu.isys413.group1E.DataException;

/**
 * Class written to contain Store information such as ID, location, phone, and manger ID.
 * @author Travis Kulbeth
 */
public class StoreBO {
    
    private String storeID;
    private String address;
    private String city;
    private String state;
    private String zip;
    private String phone;
    private String managerID;
    boolean alreadyInDB;
    boolean isDirty;
    
    /** Creates a new instance of StoreBO */
    public StoreBO() {
    }
    
    /**
     * Creates a new instance of StoreBO
     * @param id contains the already existing id for the store object to be created
     */
    public StoreBO(String id) {
        this.storeID = id;
        this.setIsDirty(true);
    }
    
    /** Retrieves the store ID from the object
     *
     * @return storeID
     */
    public String getStoreID() {
        return storeID;
    }

    /** sets the storeID
     * 
     * @param storeID contains a GUID string
     */
    public void setStoreID(String storeID) {
        setIsDirty(true);
        this.storeID = storeID;
    }

    /**
     * Retrieves the store address
     * @return address
     */
    public String getAddress() {
        return address;
    }

    /** Sets the store address
     * 
     * @param address contains the address for the Store.
     */
    public void setAddress(String address) {
        setIsDirty(true);
        this.address = address;
    }

    /**
     * Returns the store city
     * @return city
     */
    public String getCity() {
        return city;
    }

    /** Sets the store city
     * 
     * @param city contains the city for the Store
     */
    public void setCity(String city) {
        setIsDirty(true);
        this.city = city;
    }

    /** Returns the store state
     * 
     * @return state
     */
    public String getState() {
        return state;
    }

    /** Sets the store state
     * 
     * @param state contains the state for the Store
     */
    public void setState(String state) {
        setIsDirty(true);
        this.state = state;
    }

    /** Returns the store zip
     * 
     * @return zip
     */
    public String getZip() {
        return zip;
    }

    /** Sets the store zip
     * 
     * @param zip contains the zipcode for the Store
     */
    public void setZip(String zip) {
        setIsDirty(true);
        this.zip = zip;
    }

    /** Returns the store zip
     * 
     * @return zip
     */
    public String getFullAddress() {
        String fullAddr = new String(this.getAddress() + ", " + this.getCity() + ", " + 
                this.getState() + " " + this.getZip());
        return fullAddr;
    }
    
    /** Returns the store phone number
     * 
     * @return phone
     */
    public String getPhone() {
        return phone;
    }

    /** Sets the store phone number
     * 
     * @param phone contains the phone number for the store
     */
    public void setPhone(String phone) {
        setIsDirty(true);
        this.phone = phone;
    }

    /** Returns the store manager's ID
     * 
     * @return managerID
     */
    public String getManagerID() {
        return managerID;
    }

    /** Sets the store manager's ID
     * 
     * @param managerID contains the GUID generated to identify the Manager in the DB.
     */
    public void setManagerID(String managerID) {
        setIsDirty(true);
        this.managerID = managerID;
    }
    
    /**
     * Returns the Manager for the current store
     * @return EmployeeBO containing the manager's employee information.
     */
    public EmployeeBO getManager(){
        EmployeeBO emp = null;
        try {
            emp = EmployeeDAO.getInstance().read(this.getManagerID());
        } catch (DataException ex) {
            ex.printStackTrace();
         } catch (ConnectionPoolException ex) {
            ex.printStackTrace();
        }
        return emp;
    }
    
    /** Sets the alreadyInDB variable to indicate that 
     * the information contained in this object has been stored in the database
     * 
     * @param is indicates whether the object exists in the DB or not
     */
    public void setAlreadyInDB(boolean is){
        setIsDirty(true);
        this.alreadyInDB = is;
    }

    /** Returns if the information contained in this object has already been stored in the database
     * 
     * @return returns alreadyInDB
     */
    public boolean isAlreadyInDB() {
        return alreadyInDB;
    }

    /** Returns if information has been changed within this object
     * 
     * @return isDirty
     */
    public boolean isIsDirty() {
        return isDirty;
    }

    /** Sets the variable isDirty to indicate that some information has been modified or changed
     *in this object
     * 
     * @param isDirty indicating if the DB needs to be updated with new info
     */
    public void setIsDirty(boolean isDirty) {
        this.isDirty = isDirty;
    }    
    
}
